package 深入反射机制.反射方法Method.反射机制调用方法.test01;

import test.UserService;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ReflectTest01 {
    public static void main(String[] args) {
        Class userServiceClass = UserService.class;

        try {
            Object obj = userServiceClass.newInstance();
            //获取Method
            Method loginMethod = userServiceClass.getDeclaredMethod("login",String.class,String.class);

            //Method调用方法    重要！重要！重要！重要！重要！重要！重要！重要！
            boolean returnBl = (boolean)loginMethod.invoke(obj,"jojo","123");

            System.out.println(returnBl ? "登录成功" : "登录失败");
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}
